/***************************************************************************
*   Copyright (C) 2009 by Steven Waslander   *
*   stevenw@uwaterloo.ca   *
*                                                                         *
***************************************************************************/

#ifndef MATRIXVECTOROPS_H_
#define MATRIXVECTOROPS_H_

#include "Matrix.h"
#include "Vec.h"


/**
 * Multiplies a matrix with a vector (result = left*right)
 * \param left The Matrix on the left-hand-side of the *
 * \param right The Vector on the right-hand-side of the *
 * \return A vector that is the result of the operation
 **/
template <class T>
static Vec<T> operator*(const Matrix<T>& left, const Vec<T>& right)
{
  Matrix<T> rightMat(right) ;               // Store the rhs vector as a matrix
  Matrix<T> resultMat( (left*rightMat) ) ;  // Perform multiplication between matricies
  return *((Vec<T>*)&resultMat) ;        // Cast the resulting matrix as a vector
}

namespace MatrixVectorOps
{
  /**
   * Extracts the specified column from a matrix
   * \param mat The matrix from which a column will be extracted
   * \param N specifies which column should be extracted. (N=0 is the first column)
   * \return A Vector holding the specified column
   **/

  template <class T>
  static Vec<T> GetMatrixColumn(const Matrix<T>& mat, int N)
  {
    int numRows = mat.NumRows() ;
    
    Vec<T> result(numRows) ;
    for(int i=0; i < numRows; i++)
    {
      result(i) = mat(i,N) ;
    }
    return result ;
  }
}

#endif /* MATRIXVECTOROPS_H_ */
